#include "list.h"

void init_list(List* list)
{
	list->head = NULL;
	list->end = NULL;
	list->count = 0;
}

bool is_full_list(const List* list)
{
	Node* tep = (Node*)malloc(sizeof(Node));
	if (tep == NULL)
		return true;
	else
		return false;
}

void copy_node(Item temp, Node* pnew)
{
	pnew->item = temp;
}

bool add_node(Item item, List* list)
{
	Node* Head = list->head;
	Node* End = list->end;
	Node* pnew = (Node*)malloc(sizeof(Node));
	if (pnew == 0)
		return false;
	copy_node(item, pnew);
	pnew->next = NULL;
	if (list->head == NULL)
	{
		list->head = pnew;
		list->end = pnew;
		list->count = 1;
	}
	else
	{
		list->end->next = pnew;
		list->end = pnew;
		list->count += 1;
	}
	return true;
}



bool is_empty_list(const List* list)
{
	if (list->head == NULL)
		return true;
	else
		return false;
}

void operate_list(List* list, void(*fun)(Node*))
{
	Node* scan = list->head;
	while (scan != NULL)
	{
		fun(scan);
		scan = scan->next;
	}
}

void free_list(List* list)
{
	Node* tmp = list->head;
	while (tmp = NULL)
	{
		tmp = list->head->next;
		free(list->head);
		list->head = tmp;
	}
}
